package com.osmino.contacts.view.list;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.osmino.contacts.R;
import com.osmino.contacts.model.contacts.IContact;
import com.osmino.contacts.model.contacts.utils.ContactUtils;
import com.osmino.contacts.view.IStyleableView;
import com.osmino.contacts.view.style.Style;

public class ContactItem extends RelativeLayout implements IStyleableView{
	
	private final int LAYOUT = R.layout.contact_item;
	
	private final int BG_ONE = R.drawable.base_list_bg_1;
	private final int BG_TWO = R.drawable.base_list_bg_2;
	
	public static final int ROOT_RL = R.id.contact_item_bg_rl;
	public static final int TEXT = R.id.contact_item_text_tv;
	public static final int PIC = R.id.contact_item_pic_iv;
	private static final int PIC_DEF = R.drawable.base_no_avatar_ic;
	
	private RelativeLayout root;
	
	public ContactItem(Activity activity, IContact contact, int position){
		super(activity);
		root = (RelativeLayout) activity.getLayoutInflater().inflate(LAYOUT, this);
//		findViewById(ROOT_RL).setBackgroundResource(position%2==0 ? BG_TWO : BG_ONE);
	}

	public void clearInfo() {
		TextView tv = (TextView)root.findViewById(TEXT);
		ImageView iv = (ImageView) root.findViewById(PIC);
		tv.setText("");
		iv.setImageResource(PIC_DEF);
	}

	public void setInfo(IContact iContact) {
		clearInfo();
		TextView tv = (TextView)root.findViewById(TEXT);
		ImageView iv = (ImageView) root.findViewById(PIC);
		tv.setText(ContactUtils.getStructuredName(iContact));
		if(iContact.getData(IContact.HAS_PHOTO_B, Boolean.class)){
			BitmapDrawable bd = iContact.getData(IContact.PHOTO_BD, BitmapDrawable.class);
			if(bd!=null){
				iv.setImageDrawable( bd );
			}
		}
	}

	@Override
	public void setStyle(Style style) {
	}
}